export default {
    menus(state) {
        let menus = state.user.userinfo.menus;
        let newMenu = {};
        // 排序
        menus.sort((a, b) => {
            return b.sort - a.sort;
        })
        for (let i = 0; i < menus.length; i++) {
            let parentId = menus[i].parentId;
            if (parentId == 0) {
                newMenu[menus[i].id] = { ...menus[i], children: newMenu[menus[i].id] && newMenu[menus[i].id].children ? newMenu[menus[i].id].children : [] };

            } else {
                newMenu[parentId] = newMenu[parentId] || {};
                newMenu[parentId].children = newMenu[parentId].children || [];
                newMenu[parentId].children.push(menus[i]);
            }
        }
        return newMenu
    },
    permission(state) {
        let menus = state.user.userinfo.menus;
        return menus.reduce((prev, current) => {
            if (current.hidden) {
                prev.push(current.name);
            }
            return prev;
        }, []);
    }
}